package StratelegoGame;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

/**
 * A splash screen for the game.
 * @author Jace Ferguson
 * @filename StratelegoSplash.java
 *
 */
public class StratelegoSplash extends JFrame implements ActionListener{
	protected Image splash;
	protected Timer timer;
	
	/**
	 * Constructor to run the splash screen and show the image.
	 */
	public StratelegoSplash()
	{
		try
		{
			this.splash = ImageIO.read(new File("images/Splash.jpg"));
		}
		catch(IOException e){}
		this.setContentPane(new getPanel(this.splash));
		this.setSize(new Dimension(this.splash.getWidth(this), this.splash.getHeight(this)));
		this.setUndecorated(true);
		this.repaint();	
		this.timer = new Timer(3000, this);
		this.timer.start();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
	/**
	 * Dispose of the window once the timer runs out.
	 */
	public void actionPerformed(ActionEvent e)
	{
		this.dispose();
	}
	/**
	 * Private class that actually paints the splash image on a JPanel
	 * @author Jace Ferguson
	 *
	 */
	class getPanel extends JPanel
	{
		private Image splash;
		
		/**
		 * Constructor to set the splash image
		 * @param splash	Image
		 */
		public getPanel(Image splash)
		{
			this.splash = splash;
		}
		/**
		 * Paint the image on the jpanel.
		 */
		public void paintComponent(Graphics g)
		{
			super.paintComponents(g);
			Graphics gr = g.create();
			if(this.splash != null)
				gr.drawImage(this.splash, 0, 0, this);
		}
	}


}


